import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //登录注册时服务器回传的用户数据
    response:null,
    //Token
    token:localStorage.getItem('userToken') || null,
    //地图单击数据
    click_data:null,
    //考核开始倒计时
    examine_status:false,
    //作答弹窗状态
    answer_pop:false,
    answer_text:null,
    //答案----用于渲染解析地图
    answer_map:null,
    //退出按钮确认
    exit_sure_status:null,
    //训练随机模式题库
    mode_topic_list:null,
    //训练名称定位模式-作答确认弹窗
    position_by_name_pop_status:false,
    //训练名称定位模式-用户单击地图区域
    position_by_name_answer_input:null,
    //训练名称定位模式-地图解析
    position_analysis:null,
    //完整未经处理的乡镇数据--传递给县区训练模式
    all_county_town_data:null,
    //打开完整的训练地图
    open_complete_train_map:false,
    //训练模式的小模式显示状态
    mode_exit_status:false,
    //试卷测验模式的作答记录------全部
    test_records_list:[],
  },
  getters: {
  },
  mutations: {
    setresponse(state,value){
      state.response= value;
    },
    setToken(state,token){
      state.token = token;
      localStorage.setItem('userToken',token)
    },
    setclick_data(state,value){
      state.response = value
    },
    setexamine_status(state,value){
      state.examine_status = value
    },
    setanswer_pop(state,value){
      state.answer_pop = value
    },
    setanswer_text(state,value){
      state.answer_text = value
    },
    setanswer_map(state,value){
      state.answer_map = value
    },
    setexit_sure_status(state,value){
      state.exit_sure_status = value
    },
    set_mode_topic(state,value){
      state.mode_topic_list = value
    },
    set_position_by_name_pop_status(state,value){
      state.position_by_name_pop_status = value
    },
    set_position_by_name_answer_input(state,value){
      state.position_by_name_answer_input = value
    },
    set_position_analysis(state,value){
      state.position_analysis = value
    },
    set_all_county_town_data(state,value){
      state.all_county_town_data = value
    },
    set_open_complete_train_map(state,value){
      state.open_complete_train_map = value
    },
    set_mode_exit_status(state,value){
      state.mode_exit_status = value
    },
    set_test_records_list(state,newdata){
      state.test_records_list.push(newdata)
    },
  },
  actions: {
    //登录注册服务器返回的登录信息
    markresponse_state({commit},value){
      commit('setresponse',value)      // 监听到setresponse_state事件时提交value值到vuex
    },
    // markresponse_state({commit}){
    //   let userinfo = localStorage.getItem('userinfo')
    //   if(userinfo){
    //     commit('setresponse',JSON.parse(userinfo))
    //   }
    // },
    //地图单击数据
    markclick_data_state({commit},value){
      commit('setclick_data',value)
    },
    markexamine_status({commit},value){
      commit('setexamine_status',value)
    },
    markanswer_pop({commit},value){
      commit('setanswer_pop',value)
    },
    markanswer_text({commit},value){
      commit('setanswer_text',value)
    },
    markanswer_map({commit},value){
      commit('setanswer_map',value)
    },
    markexit_sure_status({commit},value){
      commit('exit_sure_status',value)
    },
    mark_mode_topic({commit},value){
      commit('set_mode_topic',value)
    },
    mark_position_by_name_pop_status({commit},value){
      commit('set_position_by_name_pop_status',value)
    },
    mark_position_by_name_answer_input({commit},value){
      commit('set_position_by_name_answer_input',value)
    },
    mark_position_analysis({commit},value){
      commit('set_position_analysis',value)
    },
    mark_all_county_town_data({commit},value){
      commit('set_all_county_town_data',value)
    },
    mark_open_complete_train_map({commit},value){
      commit('set_open_complete_train_map',value)
    },
    mark_mode_exit_status({commit},value){
      commit('set_mode_exit_status',value)
    },
    add_test_records_list({commit},value){
      commit('set_test_records_list',value)
    },
  },
  modules: {
  }
})
